home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d22 / diskedit.arc / KEYS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-06  |  1.9 KB  |  83 lines

  1. /* keys.c - keyboard input and function key translation */
  2. /* lrs - 2/13/89 */
  3.  
  4. #include <stdio.h>
  5. #include <bios.h>
  6. #include <ctype.h>
  7. #include "keys.h"
  8. #include "video.h"
  9. /*-----------------------------------------------------------------------*/
  10. int getcmd(void)
  11.   {
  12.   int ch;
  13.  
  14.   ch = bioskey(0);
  15.   if ((ch & 0xFF) !=0) /* not a function key */
  16.     {
  17.     ch &= 0xFF;
  18.     return (toupper(ch));
  19.     }
  20.   else
  21.     return(ch);
  22.   }    /* getcmd */
  23. /*-----------------------------------------------------------------------*/
  24. unsigned char getkey(char prompt[])
  25.   {
  26.   unsigned char ch;
  27.  
  28.   at(screenrows()-2,0); in(REVERSE);
  29.   cprintf(prompt);
  30.   in(NORMAL); cleareol();
  31.   ch = getcmd();
  32.   at(screenrows()-2,0); cleareol();
  33.   return(ch);
  34.   } /* getkey */
  35. /*-----------------------------------------------------------------------*/
  36. void getline(char prompt[], char line[])
  37.   {
  38.   at(screenrows()-2,0); in(REVERSE);
  39.   cprintf(prompt);
  40.   in(NORMAL); cleareol();
  41.   gets(line);
  42.   at(screenrows()-2,0); cleareol();
  43.   } /* getline */
  44. /*-----------------------------------------------------------------------*/
  45. void getdec(char prompt[], int* num)
  46.   {
  47.   char tmpstr[20];
  48.   
  49.   getline(prompt, tmpstr);
  50.   if (tmpstr[0] != 0)
  51.     *num = atoi(tmpstr);
  52.   }  /* getdec */
  53. /*-----------------------------------------------------------------------*/
  54. int atoh(char* tmpstr)
  55.   {
  56.   int done, tmpnum;
  57.   char ch;
  58.   done = tmpnum = 0;
  59.   
  60.   while (!done)
  61.     {
  62.     ch = toupper(*tmpstr++);
  63.     if ((ch >= '0') && (ch <= '9'))
  64.       tmpnum = (tmpnum*0x10) + (ch-'0');
  65.     else if ((ch >= 'A') && (ch <= 'F'))
  66.       tmpnum = (tmpnum*0x10) + (ch-'A'+10);
  67.     else
  68.       done = 1;
  69.     }
  70.   return(tmpnum);
  71.   } /* atoh */
  72.  
  73. void gethex(char prompt[], int* num)
  74.   {
  75.   char tmpstr[20];
  76.   
  77.   getline(prompt, tmpstr);
  78.   if (tmpstr[0] != 0)
  79.     *num = atoh(tmpstr);
  80.   } /* gethex */
  81.  
  82. /*---- end of keys.c ----*/
  83.